package com.shtel.paas.monitorcenter.system.management.user.management.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.shtel.paas.monitorcenter.system.management.user.management.entity.LogUserRoleEntity;
import com.shtel.paas.monitorcenter.system.management.user.management.service.RoleAndAuthorityManagementService;
import com.shtel.paas.monitorcenter.util.Page;
import com.shtel.paas.sdk.core.RefreshableRestController;
import com.shtel.paas.sdk.core.mybatis.EnablePaasMybatis;

/**
* @author: zhangyy
* 2018年5月17日
* monitorCenterWeb--角色权限管理页面controller
*/

@EnablePaasMybatis
@MapperScan("com.shtel.paas.monitorcenter.system.management.user.management.mapper")
@RefreshableRestController
public class RoleAndAuthorityManagementController {
	@Autowired
	private RoleAndAuthorityManagementService roleAndAuthorityManagementService;

	/**
	 * 查询所有角色
	 * 
	 * @param paramter
	 * @return result
	 */
	@GetMapping("/getRoles")
	public Page<LogUserRoleEntity> getRoles(String roleName,Integer page,Integer pageSize) {

		Page<LogUserRoleEntity> pageContent = roleAndAuthorityManagementService.getRoles(roleName,page,pageSize);
		return pageContent;
	}

	/**
	 * 创建角色
	 * 
	 * @param paramter
	 * @return result
	 */
	@RequestMapping("/createRole")
	public Integer createRole(
			@RequestParam("createTime") Date createTime,
			@RequestParam("updateTime") Date updateTime,
			@RequestParam("state") String state,
			@RequestParam("code") String code,
			@RequestParam("name") String name,
			@RequestParam("description") String description,
			@RequestParam("mIds") String mIds
			) {
		LogUserRoleEntity logUserRoleEntity=new LogUserRoleEntity();
		UUID uuid = UUID.randomUUID();
		logUserRoleEntity.setId(uuid+"");
		logUserRoleEntity.setCode(code);
		logUserRoleEntity.setCreateTime(createTime);
		logUserRoleEntity.setDescription(description);
		logUserRoleEntity.setName(name);
		logUserRoleEntity.setState(state);
		logUserRoleEntity.setUpdateTime(updateTime);
		logUserRoleEntity.setMenuIds(mIds);
		return roleAndAuthorityManagementService.createRole(logUserRoleEntity);
		
	}
	



	/**
	 * 角色单个删除
	 */
	@GetMapping("/deleteRoleByIds")
	public Integer deleteRoleByIds(@RequestParam("del_ids") String del_ids) {
	
		//Integer String = uerManagementService.deleteByIdsAndUserNo(rmpEnt);
		return roleAndAuthorityManagementService.deleteRoleByIds(del_ids);
		
	}

	/**
	 * 角色批量删除
	 */
	@GetMapping("/deleteRoleBatch")
	public Integer deleteRoleBatch(@RequestParam("del_ids") String del_ids) {
		List<String> emp = new ArrayList<>();

		// 参数调整
		if (del_ids.contains(",")) {
			String[] ids = del_ids.split(",");
			for (int i = 0; i < ids.length; i++) {
				if (ids[i] != null || ids[i] != "") {
					emp.add(ids[i]);
				}
			}
		}
		return roleAndAuthorityManagementService.deleteRoleBatch(emp);
		
	}

	/**
	 * 更改角色权限
	 * 
	 * @param paramter
	 * @return result
	 */
	@GetMapping("/changeRolePermissions")
	public Integer changeRolePermissions(
			@RequestParam("id") String id,
			@RequestParam("createTime") Date createTime,
			@RequestParam("updateTime") Date updateTime,
			@RequestParam("state") String state,
			@RequestParam("code") String code,
			@RequestParam("name") String name,
			@RequestParam("description") String description,
			@RequestParam("mIds") String mIds
			) {
		LogUserRoleEntity logUserRoleEntity=new LogUserRoleEntity();
	
		logUserRoleEntity.setId(id);
		logUserRoleEntity.setCode(code);
		logUserRoleEntity.setCreateTime(createTime);
		logUserRoleEntity.setDescription(description);
		logUserRoleEntity.setName(name);
		logUserRoleEntity.setState(state);
		logUserRoleEntity.setUpdateTime(updateTime);
		logUserRoleEntity.setMenuIds(mIds);
		return roleAndAuthorityManagementService.changeRolePermissions(logUserRoleEntity);
	}

	
	/**
	 * 查询menu列表整体
	 * @param 
	 * @return Object
	 */
	@GetMapping("/getMenus")
	public Object getMenus(){
		return roleAndAuthorityManagementService.getMenus();
		
	}
	
}
